package wcg;

import java.awt.BorderLayout;
import java.awt.FlowLayout;
import java.awt.Frame;

import javax.swing.JButton;
import javax.swing.JDialog;
import javax.swing.JPanel;
import javax.swing.border.EmptyBorder;
import javax.swing.JTextPane;
import javax.swing.JLabel;
import javax.swing.JTextField;
import java.awt.event.ActionListener;
import java.awt.event.ActionEvent;
import javax.swing.SwingConstants;
import java.awt.Toolkit;
import java.awt.Dialog.ModalityType;
import javax.swing.ImageIcon;


public class DialogMarkerAddSpecialParameter extends JDialog {

	private final JPanel contentPanel = new JPanel();
	private JTextField textFieldInterval;
	private JTextField textFieldNumber;
	public boolean OK=false;
	public int Interval=1;
	public int Number=1;
	/**
	 * Launch the application.
	 */
//	public static void main(String[] args) {
//		try {
//			DialogMarkerAddSpecialParameter dialog = new DialogMarkerAddSpecialParameter();
//			dialog.setDefaultCloseOperation(JDialog.DISPOSE_ON_CLOSE);
//			dialog.setVisible(true);
//		} catch (Exception e) {
//			e.printStackTrace();
//		}
//	}

	/**
	 * Create the dialog.
	 */
	public DialogMarkerAddSpecialParameter(Frame owner) {
		super(owner);
		setModalityType(ModalityType.DOCUMENT_MODAL);
//		setType(Type.POPUP);
		setTitle("Add marker special");
		setResizable(false);
		setIconImage(Toolkit.getDefaultToolkit().getImage(DialogMarkerAddSpecialParameter.class.getResource("/images/marker.png")));
		setBounds(100, 100, 584, 299);
		getContentPane().setLayout(new BorderLayout());
		contentPanel.setBorder(new EmptyBorder(5, 5, 5, 5));
		getContentPane().add(contentPanel, BorderLayout.CENTER);
		contentPanel.setLayout(null);
		
		JLabel lblIntervalTimesec = new JLabel("Interval [sec]");
		lblIntervalTimesec.setBounds(360, 162, 97, 19);
		contentPanel.add(lblIntervalTimesec);
		
		JLabel lblAddMarkerNumber = new JLabel("Number of Marker");
		lblAddMarkerNumber.setBounds(359, 182, 129, 24);
		contentPanel.add(lblAddMarkerNumber);
		
		textFieldInterval = new JTextField();
		textFieldInterval.setToolTipText("Interval time between each marker.");
		textFieldInterval.setHorizontalAlignment(SwingConstants.CENTER);
		textFieldInterval.setText("10");
		textFieldInterval.setBounds(508, 164, 58, 19);
		contentPanel.add(textFieldInterval);
		textFieldInterval.setColumns(10);
		
		textFieldNumber = new JTextField();
		textFieldNumber.setToolTipText("Number of marker to add following reference marker.");
		textFieldNumber.setHorizontalAlignment(SwingConstants.CENTER);
		textFieldNumber.setText("5");
		textFieldNumber.setBounds(507, 187, 58, 19);
		contentPanel.add(textFieldNumber);
		textFieldNumber.setColumns(10);
		
		JLabel lblNewLabel = new JLabel("New label");
		lblNewLabel.setIcon(new ImageIcon(DialogMarkerAddSpecialParameter.class.getResource("/images/AddSpecialMarker.PNG")));
		lblNewLabel.setBounds(0, 0, 348, 221);
		contentPanel.add(lblNewLabel);
		
		JTextPane txtpnaddMarkerSpecial = new JTextPane();
		txtpnaddMarkerSpecial.setEditable(false);
		txtpnaddMarkerSpecial.setText(" \"Add marker special\" adds marker(s) following the reference marker. \r\n This function is useful for picking up data using markers.\r\n To pick up data, try \"Copy marker Average to Clipboad\" in right click menu on Time-chart View of time display area.");
		txtpnaddMarkerSpecial.setBounds(365, 4, 212, 154);
		contentPanel.add(txtpnaddMarkerSpecial);
		{
			JPanel buttonPane = new JPanel();
			buttonPane.setLayout(new FlowLayout(FlowLayout.RIGHT));
			getContentPane().add(buttonPane, BorderLayout.SOUTH);
			{
				JButton okButton = new JButton("OK");
				okButton.addActionListener(new ActionListener() {
					public void actionPerformed(ActionEvent arg0) {
						OK=true;
						String str= textFieldInterval.getText();
						Interval = Integer.parseInt(str);
						str= textFieldNumber.getText();
						Number =  Integer.parseInt(str);
						dispose();
					}
				});
				okButton.setActionCommand("OK");
				buttonPane.add(okButton);
			}
			{
				JButton cancelButton = new JButton("Cancel");
				cancelButton.addActionListener(new ActionListener() {
					public void actionPerformed(ActionEvent e) {
						dispose();
					}
				});
				cancelButton.setActionCommand("Cancel");
				buttonPane.add(cancelButton);
				getRootPane().setDefaultButton(cancelButton);
			}
		}
	}
	public void SetValue(){
		textFieldInterval.setText(String.valueOf(Interval));
		textFieldNumber.setText(String.valueOf(Number));
	}
}
